﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;

namespace net461
{
    public class TestClass
    {
        public static string TestName = "关山";

        public void Say()
        {
            Console.WriteLine("name:" + TestName);
        }
    }

    public static class StaticClass
    {
        private static IFormatProvider Str { get; set; }
        public static string CalUserAge()
        {
            User a = new User();
            return a.GetName();
        }
    }

    [Serializable]
    public class DemoClass
    {
        public int i = 0;
        public int[] iArr = { 1, 2, 3 };

        public DemoClass Clone1() //浅clone
        {
            return this.MemberwiseClone() as DemoClass;
        }

        public DemoClass Clone2() //深clone         
        {
            MemoryStream stream = new MemoryStream();
            BinaryFormatter formatter = new BinaryFormatter();
            formatter.Serialize(stream, this);
            stream.Position = 0;
            return formatter.Deserialize(stream) as DemoClass;
        }
    }
    public class TreeNode
    {
        public int val;
        public TreeNode left;
        public TreeNode right;
        public TreeNode(int x) { val = x; }
    }
    public class ListNode
    {
        public int val;
        public ListNode next;
        public ListNode(int x) { val = x; }

        /// <summary>
        /// 创建操作(头插法创建链表)
        /// </summary>
        public ListNode CreateListTail(List<int> intList)
        {
            if (intList == null || intList.Count <= 0)
                return null;
            ListNode res = null;
            foreach (var item in intList)
            {
                ListNode temp = new ListNode(item);
                //if (res == null)
                //    res = temp;
                //else
                //{
                //    res.next = temp;
                //}
                //res = temp;
                temp.next = res;
                res = temp;
            }
            return res;
        }
    }
}